package com.dc.refactoring._1_重新组织函数._8_ReplaceMethodWithMethodObject;

/**
 * Description: 以函数对象取代函数_新构建的 函数对象
 * @author: gdc
 * @date: 2020/11/13
 * @version 1.0
 */
public class Gamma {
    /**
     * 保存员对象
     */
    private final Account account;

    /**
     * 保存对应的 原参数
     */
    private int inputVal;
    private int quantity;
    private int yearToDate;

    /**
     * 保存对应的临时参数
     */
    private int importantValue1;
    private int importantValue2;
    private int importantValue3;

    public Gamma(Account account, int inputVal, int quantity, int yearToDate) {
        this.account = account;
        this.inputVal = inputVal;
        this.quantity = quantity;
        this.yearToDate = yearToDate;
    }

    /**
     * 改造后的计算逻辑
     */
    public int compute() {
        importantValue1 = (inputVal * quantity) + account.delta();
        importantValue2 = (inputVal * yearToDate) + 100;

        // 函数提炼，此时不需担心参数传递的问题
        if ((yearToDate - importantValue1) > 200) {
            importantValue2 -= 20;
        }

        importantValue3 = importantValue2 * 7;
        return importantValue3 - 2 * importantValue1;
    }

}
